package com.cenntro.common.thread;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description: 运行线程池
 */
public class ThreadPool extends ThreadPoolExecutor {
	private static BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(200);
	private static ThreadPool threadPool = new ThreadPool(8, 30, 10000,
			TimeUnit.MILLISECONDS, queue);

	/**
	 * 
	 */
	private static ScheduledExecutorService timer = Executors.newScheduledThreadPool(50);
			
	public ThreadPool(int corePoolSize, int maximumPoolSize,
			long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
		super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
	}

	public static ThreadPool getInstance() {
		return threadPool;
	}

	@Override
	public void execute(Runnable command) {
		super.execute(command);
	}
	
	public <V> Future<V> scheduleAtFixedRate(Runnable command)throws Exception {
		Future<V> f= (Future)timer.scheduleAtFixedRate(command, 1, 1, TimeUnit.SECONDS);
		System.out.println(f);
		return f;
	}

	public static void main(String[] args) throws Exception {
	}
}
